<?php

namespace common\models\business;

use Yii;

/**
 * This is the model class for table "business_contract_field".
 *
 * @property string $id
 * @property integer $cateid
 * @property string $name
 * @property string $type
 * @property integer $length
 * @property string $comment
 */
class BusinessContractField extends \yii\db\ActiveRecord
{

    //主要用于日志记录
    public $uselog = [
        'tabcomment' => '合同附加字段',      //用于修改了什么的显示
        'mainfield' => 'title',      //主要的显示标题的字段
        'picturefield' => [],        //图片字段
        'timefield' => [],       //时间字段
        'unsetfiled' =>[],      //不需要记录的字段
    ];

    public static $types = [
        'varchar' => '字符串',
        'int' => '整数',
        'decimal' => '浮点型'
    ];


    public static $viewtypes = [
        '附件','文本框','时间'
    ];



    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'business_contract_field';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['cateid', 'name', 'comment'], 'required'],
            [['cateid', 'length'], 'integer'],
            ['name', 'unique'],
            ['viewtype', 'default', 'value' => 0], #说明:CDefaultValueValidator 的别名, 为特性指派了一个默认值.
            ['length', 'default', 'value' => 30], #说明:CDefaultValueValidator 的别名, 为特性指派了一个默认值.
            ['type', 'default', 'value' => 'varchar'], #说明:CDefaultValueValidator 的别名, 为特性指派了一个默认值.
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'cateid' => '所属合同分类',
            'name' => '字段名字',
            'type' => '类型',
            'length' => '长度',
            'comment' => '说明',
            'viewtype' => '展示类型',
        ];
    }


    /**
     * @return array|\yii\db\ActiveRecord[]
     * 取出所有分类
     */
    public static function AllCate()
    {
        return BusinessContractCategory::find()->all();

    }


    /**
     * @return \yii\db\ActiveQuery
     * 获取合同分类
     */
    public function getCategory()
    {
        return $this->hasOne(BusinessContractCategory::className(),['id'=>'cateid']);
    }


}
